﻿Imports System.Data.OleDb
Public Class Connect

    Protected Function ConnectionData() As OleDbConnection
        Try
            Dim str As String
            str = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = PTNK.mdb"
            Dim cn As New OleDbConnection(str)
            cn.Open()
            Return cn
        Catch ex As OleDbException
            Throw New Exception(ex.Message.ToString)
        End Try
    End Function
    Function LayMa(ByVal tenbang As String, ByVal tencot As String, ByVal kytu As String) As String
        Dim cn As New OleDbConnection
        cn = Me.ConnectionData()
        Dim sql As String
        sql = "select " & tencot & " from " & tenbang
        Dim dt As New DataTable
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        Dim sl As Integer = dt.Rows.Count
        Dim str As String = dt.Rows(sl - 1).Item(0).ToString
        Dim maso As String = str.Substring(2)
        maso = (CType(maso, Integer) + 1).ToString
        Dim ma = kytu + maso
        Return ma
    End Function
    Public Sub New()

    End Sub
End Class
